/**
/**
 * Created by King_Vicent on 2018/7/30.
 */
var vm = new Vue({
    el: '#rrapp',
    data :function() {
        return {
            isList: true, // 表格
            index: "", // 表格
            isDetail: false, // 详情
            isAdd: false, // 新增
            lists: 'primary',
            question: '',
            history: '',
            isDcList: true,
            isQuestion: false,
            isHistory: false,
            pageTitle: '', // 块标题
            tableData:[], // 获取表格数据
            pageNo: 1, // 当前页
            totalPage: 0, // 总页数
            pageSize: 10, // 每页数据条数
            findKey: '', // 搜索关键字
            baseForm: {
                titleName: '',
                msgFlag: 1,
                dcssfs:0,
                wtzz:1,
                description: '',
                ssfwCheckedList: [],
                jzrq: '',
                ids: []
            },
            detailId: '',
            lookTitle: '', // 都查记录详情 标题
//            lookTime: '2018-04-29', // 都查记录详情 新增日期
            lookUpdateTime: '', // 都查记录详情 新增日期
            lookCorp: '', // 都查记录详情 单位
            lookStatus: '', // 都查记录详情 状态
            lookPercent: '', // 百分比
            dataKind:'',//选择的类型（督察记录，问题追踪，整改历史）

        }
    },
    mounted:function() {
        this.getData();
    },
    methods: {
        // 获取数据
        getData: function(clickType, methodType) { // clickType 顶部按钮类型
        	 if (methodType == 'pageChange') {
        		 clickType = this.dataKind;
        	 }
        	 //console.log(this.dataKind);
        	 var url = baseURL;
             if (clickType === undefined) {
             	url = url +'business/superviserecord/listMultiple';
             } else if (clickType === 0) {
             	url = url +'business/supervisequestion/listMultiple';
             } else if (clickType === 1) {
             	url = url +'business/supervisequestionmodify/listMultiple';
             }
             
            var params = {
                name: this.findKey,
                currPage: this.pageNo,
                pageSize: 10
                // type: type // 类型
            };
            //debugger;
           
            
            $.ajax({
                type: "GET",
                url: url,
                data:params,
                contentType: "application/json",
                success: function (res) {
                    if (res.code === '0') {
                        vm.tableData = res.page.list;
                        vm.totalPage = res.page.totalPage;
                        vm.pageNo = res.page.currPage;
                        //vm.baseForm.zbdw = res.sessionUser.deptName
                        //vm.baseForm.zbdwId = res.sessionUser.deptId;
                        //console.log(res.sessionUser);
                        //vm.roleName = res.sessionUser.roleName;
                        //vm.wtzz = RegExp(/B/).test(res.sessionUser.roleName);
                        //vm.xz = vm.wtzz
                        //vm.zgls = RegExp(/A/).test(res.sessionUser.roleName);
                        vm.dataKind = clickType;
                    } else {
                        alert(res.msg);
                    }
                }
            });
        },
        
        // 整改状态(0：待整改，1：无整改，2：已整改
        formatModifyStatus: function (row, column) {
            switch(row.v4){
	            case '0' : return '待整改';
	            case '1' : return '无整改';
	            case '2' : return '已整改';
	            default : return '未知<';
            }
        },
        
        // 审核状态(0：待审核，1：审核通过，2：审核未通过)
        formatSHStatus: function (row, column) {
            switch(row.v4){
	            case '0' : return '待审核';
	            case '1' : return '审核通过';
	            case '2' : return '审核未通过';
	            default : return '未知<';
            }
        },
        
        //督察记录方式(1：问题随拍，2：专项督察，3：队伍管理，4：执法执勤，5：社会管控，6：其他督察)
        dcfsStatus:function(row, column) {
        	switch(row.v5){
            	case '1' : return '问题随拍';
            	case '2' : return '专项督察';
            	case '3' : return '队伍管理';
            	case '4' : return '执法执勤';
            	case '5' : return '社会管控';
            	case '6' : return '其他督察';
            	case '7' : return '每日必查';
            	default : return '未知<';
        	}
        },
        
        filterModifyStatus:function(value, row) {
            return row.v4 === value;
        },
        filterDcfsStatus:function(value, row) {
            return row.v5 === value;
        },
        filterCheckStatus:function(value, row) {
            return row.v4 === value;
        },
        // 搜索
        search :function(types, keys) {

            var params = {
                findKey: keys || vm.findKey
                
            }
            console.log(params)
            var clickType = vm.dataKind;
            var url = baseURL;
            if (clickType === undefined) {
            	url = url +'business/superviserecord/listMultiple';
            } else if (clickType === 0) {
            	url = url +'business/supervisequestion/listMultiple';
            } else if (clickType === 1) {
                url = url +'business/supervisequestionmodify/listMultiple';
            }
            $.ajax({
                type: "GET",
                url: url,
                data: params,
                contentType: "application/json",
                success: function (res) {
                    if (res.code === '0') {
                        vm.tableData = res.page.list
                        vm.totalPage = res.page.totalPage
                        vm.pangeNo = res.page.currPage
                        vm.dataKind = clickType;
                    } else {
                    	alert(res.msg);
                    }
                }
            });
        },
        indexMethod:function(index){
            return (vm.pageNo - 1) * vm.pageSize + (index + 1);
        },
        // 分页
        pageChange: function () {
            vm.getData('', 'pageChange');
        },

        // 按钮切换表格数据
        handleClick :function(clickType) {
        	vm.dataKind = clickType;
        	vm.pageNo = 1;
            //debugger
            if (clickType === undefined) {
                // 全部
                vm.lists = 'primary'
                vm.question = ''
                vm.history = ''
                vm.isDcList = true
                vm.isQuestion = false
                vm.isHistory = false            
            } else if (clickType === 0) {
                // 我的立项
                vm.lists = ''
                vm.question = 'primary'
                vm.history = ''
                vm.isDcList = false
                vm.isQuestion = true
                vm.isHistory = false
            } else if (clickType === 1) {
                // 我的审批
                vm.lists = ''
                vm.question = ''
                vm.history = 'primary'
                vm.isDcList = false
                vm.isQuestion = false
                vm.isHistory = true
            }
            console.log(vm.isHistory);
            vm.getData(clickType)
        },

        // 查看立项详情
        handleView :function(index, row,type) {
            var title = "";
            var clickType;
            if (type === 1) {
                title = "督察记录";
                clickType = undefined;
            } else if (type ===2){
                title = "督察问题";
                clickType = 0;
            } else {
                title = "整改历史";
                clickType = 1;
            }
            console.log("row:"+row.id)
            layer.open({
                title : title,
                type : 2,
                fixed: true,
                shadeClose: true,
                area : [ "100%", "100%" ],
                content : baseURL + '/business/supervise/recordDetails?id='+row.id + "&type=" +type,
                end: function () {
                	debugger;
               	 	//console.log(this.dataKind);
               	 	var url = baseURL;
                    if (clickType === undefined) {
                    	url = url +'business/superviserecord/listMultiple';
                    } else if (clickType === 0) {
                    	url = url +'business/supervisequestion/listMultiple';
                    } else if (clickType === 1) {
                    	url = url +'business/supervisequestionmodify/listMultiple';
                    }
                    
                   var params = {
                       name: this.findKey,
                       currPage: this.pageNo,
                       pageSize: 10
                       // type: type // 类型
                   }
                   //debugger;
                  
                   $.ajax({
                       type: "GET",
                       url: url,
                       data:params,
                       contentType: "application/json",
                       success: function (res) {
                           if (res.code === '0') {
                               vm.tableData = res.page.list;
                               vm.totalPage = res.page.totalPage;
                               vm.pageNo = res.page.currPage;
                               vm.dataKind = clickType;
                           } else {
                               alert(res.msg);
                           }
                       }
                   });
                }
            });
            /*vm.pageTitle = '督察记录'
            vm.isDetail = true
            vm.isAdd = false
            vm.isList = false*/

            // ajax 三个接口
            // $.ajax({
            //     type: "GET",
            //     url: baseURL + 'business/superviseproject/getSuperviseRecord',
            //     data: params,
            //     contentType: "application/json",
            //     success: function (res) {
            //         if (res.code === '0') {
            //             vm.historyData = res.data
            //         } else {
            //             alert(res.msg);
            //         }
            //     }
            // });
        },

        // 新增立项
        addProject :function() {
                vm.index = layer.open({
                    title : "新增记录",
                    type : 2,
                    fixed: true,
                    shadeClose: true,
                    area : [ "100%", "100%" ],
                    content : baseURL + '/business/supervise/addRecord',
                    end: function() {
                    	location.reload();
                    }
                });
        },

        // 取消
        cancel :function() {
            vm.pageTitle = ''
            vm.isDetail = false
            vm.isAdd = false
            vm.isList = true
            vm.baseForm = {
                titleName: '',
                msgFlag: 1,
                dcssfs:0,
                wtzz:1,
                description: '',
                ssfwCheckedList: [],
                jzrq: '',
                ids: []
            }
        },

    }
})